<template>
  <uni-nav-bar title="钱包" color="#333" :border="false" statusBar></uni-nav-bar>
  <view class="column" style="background-color: #39A8FF;color:#fff;padding:50rpx 30rpx;box-sizing: border-box;">
    <!--   <view class="column" @click="navTo('Sale/account/detail?type=count&name=累计收入&money='+Profit.count)">
      <view>累计收入<uni-icons type="forward" size="15" color="#fff"></uni-icons></view>
      <view style="font-size: 48rpx;">{{Profit.count}}</view>
    </view> -->
    <view class="column" @click="navTo('Sale/salary/salaryDetail?title='+title+'&month='+month)">
      <view>本月收入<uni-icons type="forward" size="15" color="#fff"></uni-icons></view>
      <view style="font-size: 48rpx;">{{Profit.count}}</view>
    </view>
    <!--  <view class="space-between" style="width: 100%;margin-top: 30rpx;">
      <view class="column" style="width: 50%;"
        @click="navTo('Sale/account/detail?type=withdrawal&name=待发放收益&money='+Profit.withdrawal)">
        <view>{{Profit.withdrawal}}</view>
        <view>待发放收益</view>
      </view>
      <view class="column" style="width: 50%;"
        @click="navTo('Sale/account/detail?type=freeze&name=待确认收益&money='+Profit.freeze)">
        <view>{{Profit.freeze}}</view>
        <view>待确认收益(元)</view>
      </view>
    </view> -->
  </view>
  <view class="package_sale" v-if="infor">
    <view class="center" @click="()=>show=!show">{{infor[0].name}} {{infor[0].value}} <uni-icons type="top" size="20"
        :style="{transform:show?'rotate(180deg)':'rotate(0deg)',marginLeft:'20rpx'}"></uni-icons></view>
    <view v-if="show" style="color:#666;margin:15rpx 0px;font-size:24rpx;">
      <view v-for="(item,index) in infor" :key="index" :style="{margin:'10rpx 0px',display:index===0?'none':'block'}">
        {{item.name}}：{{item.value}}
      </view>
    </view>
  </view>
  <view class="package_sale" style="padding: 0rpx 30rpx;">
    <view class="space-between lis" v-for="(item,index) in rewardList" :key="index"
      @click="navTo('Sale/account/detail?name='+item.title+'&money='+item.money+'&title='+title+'&type='+item.type+'&month='+month)">
      <view>{{item.title}}</view>
      <view>{{item.money}}</view>
    </view>
  </view>
  <SaleButtom active="3"></SaleButtom>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import SaleButtom from '@c/pobulic/saleButtom.vue'
  import { navTo } from '@/utils/navigator';
  import { format } from 'date-fns';
  import { getWagesData, getWagesInfo, getXishu } from '@/gql/earthPushing/attendance';
  import { toPublish } from '@mqtt';
  import { showLoading } from '@/utils/prompt';
  import { onPullDownRefresh } from '@dcloudio/uni-app';
  import { getDriverID } from '@/stores/driverID';
  const staff_id = getDriverID();
  // data
  const now = new Date();
  let end = format(now, 'yyyy-MM-dd').split('-');
  const month = end[0] + '-' + end[1]
  const title = end[1] + '月'
  const rewardList = ref()
  const show = ref(false)

  const infor = ref()

  const Profit = ref('')
  onPullDownRefresh(() => {
    init()
    uni.stopPullDownRefresh();
  })
  init()
  function init() {
    showLoading()
    const payload = {
      query: getWagesData,
      variables: {
        staff_id,
        month
      },
    };
    toPublish(
      'ql/staff/getWagesData',
      payload,
      (obj : any) => {
        const { getWagesData } = obj.data;
        Profit.value = getWagesData
      },
    );
  }
  xishu()
  function xishu() {
    showLoading()
    const payload = {
      query: getXishu,
      variables: {
        staff_id,
        month
      },
    };
    toPublish(
      'ql/staff/getXishu',
      payload,
      (obj : any) => {
        const { getXishu } = obj.data;
        infor.value = getXishu
      },
    );
  }
  income()
  function income() {
    showLoading()
    const payload = {
      query: getWagesInfo,
      variables: {
        staff_id,
        month
      },
    };
    toPublish(
      'ql/staff/getWagesInfo',
      payload,
      (obj : any) => {
        const { getWagesInfo } = obj.data;
        rewardList.value = getWagesInfo
      },
    );
  }
  /**
   * 时间筛选数据信息
   */
  // function change([sta, en]) {
  //   rewardList.value = [];
  //   start = sta;
  //   end = en;
  //   income()
  // }
</script>

<style scoped lang="less">
  .lis {
    padding: 35rpx 0px;
    box-sizing: border-box;
  }
</style>
<style>
  .datas>>>.uni-date__x-input {
    font-size: 30rpx !important;
  }

  .datas>>>.uni-date-x {
    font-size: 30rpx !important;
  }

  .datas>>>.uni-icons {
    font-size: 48rpx !important;
  }
</style>